package com.hyts.apidoc.swagger.html;

import com.hyts.apidoc.swagger.factory.adoc.AsciidoctorFactory;
import com.hyts.apidoc.swagger.factory.markup.Swagger2MarkupFactory;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.apidoc.swagger.html
 * author:Libo/Alex
 * create-date:2019-05-12 09:18
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: swagger ui api doc 文档操作
 */
public class HtmlDocTransfer {

    /**
     * @param swaggerYml
     * @param outputFilePath
     */
    public void createHtml(String swaggerYml,String outputFilePath){
        //判断扩展名
        if(outputFilePath.endsWith(".yml") || outputFilePath.endsWith(".yaml")){
            outputFilePath = outputFilePath.replace(".yml","")
                                           .replace(".yaml","");
        }
        Swagger2MarkupFactory.newInstance().create().
                converter(
                        swaggerYml,
                        outputFilePath);
        AsciidoctorFactory.newInstance().create().convertHtmlFromAscii(
                outputFilePath+".adoc",
                outputFilePath.concat(".html"));
    }
}
